set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}/plugin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE}/plugin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG}/plugin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE}/plugin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG}/plugin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE}/plugin)

set(PluginPrefix "Plugin-")
file(GLOB pluginPaths ./*)
foreach(plugin ${pluginPaths})
    if (NOT IS_DIRECTORY  "${plugin}")
       continue()
    endif ()

    if (NOT EXISTS "${plugin}/CMakeLists.txt")
        continue()
    endif ()

    cmake_path(GET plugin STEM name)
    add_subdirectory(${name})
endforeach()

function(CreatePlugin _RelativePath)
    set(CreatePath "${CMAKE_CURRENT_SOURCE_DIR}/${_RelativePath}")
    if (EXISTS  "${CreatePath}")
        return()
    endif ()

    cmake_path(GET CreatePath STEM OriginPluginName)
    string(TOUPPER ${OriginPluginName} UpperPluginName)
    set(PluginClassName ${OriginPluginName}Plugin)

#    TODO 暂未处理多级目录和现有插件目录情况
    file(MAKE_DIRECTORY "${CreatePath}")
    file(MAKE_DIRECTORY "${CreatePath}/include")
    file(MAKE_DIRECTORY "${CreatePath}/src")
    configure_file(${CMAKE_SOURCE_DIR}/template/PluginTemplate/include/Global.h.in
            ${CreatePath}/include/${OriginPluginName}Global.h
            @ONLY
    )
    configure_file(${CMAKE_SOURCE_DIR}/template/PluginTemplate/include/PluginTemplate.json.in
            ${CreatePath}/include/${PluginClassName}.json
            @ONLY
    )
    configure_file(${CMAKE_SOURCE_DIR}/template/PluginTemplate/src/PluginTemplate.cc.in
            ${CreatePath}/src/${PluginClassName}.cc
            @ONLY
    )
    configure_file(${CMAKE_SOURCE_DIR}/template/PluginTemplate/src/PluginTemplate.h.in
            ${CreatePath}/src/${PluginClassName}.h
            @ONLY
    )
    configure_file(${CMAKE_SOURCE_DIR}/template/PluginTemplate/CMakeLists.txt.in
            ${CreatePath}/CMakeLists.txt
            @ONLY
    )
endfunction()

#CreatePlugin(Gui)